var $= require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');

module.exports = $;

var Swipers = require('./components/swiper/swiper.min');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min');
var IScroll = require('./components/iscroll/iscroll');
var wx = require('./components/jweixin/jweixin');

var timer;
var swiper = new Swiper ('.swiper-container', {
  onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
    swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
    swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
  }, 
  onSlideChangeEnd: function(swiper){ 
    swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
    
    if(swiper.activeIndex==2){
      $('.meinfo p').html(' ');
      var str='本人性格开朗、积极勤奋，拥有充实的专业技能，工作态度认真。热爱于程序设计,了解HTML4、HTML5、ES5、ES6、CommonJS、CMD、AMD等规范、熟悉Jquery、Zepto、AngularJs、Recat、Avalon等框架、熟悉Swiper、Iscroll等类库、熟悉Jquery menu plugin、Jquery nav plugin、zepto emoji-expression-plugin等插件。';
      var arr=str.split('');
      setTimeout(function(){
        var j=0;
        var html='';
        timer=setInterval(function(){
          html+=arr[j];
          $('.meinfo p').html(html);
          j++;
          if(j>=arr.length){
            clearInterval(timer);
          }
        },100)
      },1800)
    }else{
        clearInterval(timer);
    }
  } 
}) 



 var swiper = new Swiper('.swiper-container', {
      pagination: '.swiper-pagination',
      paginationClickable: true
  });

   
    function isPassive() {
        var supportsPassiveOption = false;
        try {
            addEventListener("test", null, Object.defineProperty({}, 'passive', {
                get: function () {
                    supportsPassiveOption = true;
                }
            }));
        } catch(e) {}
        return supportsPassiveOption;
    }


  $(".close").tap(function(){

      myScroll = new IScroll('#wrapper', {
        scrollbars: true,
        mouseWheel: true,
        interactiveScrollbars: true,
        shrinkScrollbars: 'scale',
        fadeScrollbars: true
      });


      document.addEventListener('touchmove', function (e) { e.preventDefault(); }, isPassive() ? {
        capture: false,
        passive: false
      } : false);

      $(".swiper-container").hide();
      $(".mainContainer").show();

      scan();
      getproject();

  })

  $('#footer div').tap(function(){
    $(this).addClass('active').siblings().removeClass('active');
    var url;
    switch ($(this).index()) {
      case 0:getproject();
        break;
      case 1:getskill();
        break;
      case 2:getwork();
        break;
      case 3:getme();
        break;
      default:
        break;
    }

   });

    function getskill(){
         $.ajax({
          type:'post',
          url:'http://www.lewisye.online/www/api/getskill.php',
          dataType:'json',
          success:function(data){
            var html='';
            for(var i=0;i<data.length;i++){
              html+='<li class="on">';
              html+='<div class="skill-title">'+data[i].category+'</div>';
              html+='<div class="skill-name">';
              html+='<span>技术：</span><span>'+data[i].name+'</span>';
              html+='</div>';
              html+='<div class="skill-all">';
              html+='<div class="skill-time"><span>时间 ：</span><span>'+data[i].time+'</span></div>';
              html+='<div class="skill-level"><span>程度：</span><span>'+data[i].level+'</span></div>';
              html+='</div>';
              html+='</li>';
            }
            $('#scroller ul').html(html);
            setTimeout(function(){
              myScroll.refresh();
            },250)
          }
        })
    }
    
    function getwork(){
      $.ajax({
        type:'post',
        url:'http://www.lewisye.online/www/api/getwork.php',
        dataType:'json',
        success:function(data){
          var html='';
          for(var i=0;i<data.length;i++){
            html+='<li class="work">'+
						'<div class="work-pic">'+
						'<img src="'+data[i].image+'" alt="">'+
						'</div>'+
						'<div class="work-name">'+data[i].name+'</div>'+
						'<div class="work-posts">'+
            '<span>岗位：</span><span>'+data[i].posts+'</span>'+
						'</div>'+
						'<div class="work-time">'+
            '<span>任职时间：</span><span>'+data[i].time+'</span>'+
						'</div>'+
						'<div class="work-peoples">'+
            '<span>人数：</span><span>'+data[i].peoples+'</span>'+
						'</div>'+
						'<div class="work-project">'+
						'<span>项目：</span>'+data[i].projects+'</span>'+
						'</div>'+
					  '</li>';
          }
          $('#scroller ul').html(html);
          setTimeout(function(){
            myScroll.refresh();
          },250)
        }
      })
    }

    function getme(){
      $.ajax({
        type:'post',
        url:'http://www.lewisye.online/www/api/getme.php',
        dataType:'json',
        success:function(data){
          var html='';
          for(var i=0;i<data.length;i++){
            html+='<li class="meli">'+
						'<img src="'+data[i].image+'" alt="">'+
						'<div class="me-name">'+
						'<span>'+data[i].name+'</span>'+
						'<p>'+data[i].description+'</p>'+
						'</div>'+
					  '</li>';
          }
          $('#scroller ul').html(html);
          setTimeout(function(){
            myScroll.refresh();
          },250)
        }
      })
    }

    function getproject(){
      $.ajax({
        url: 'http://www.lewisye.online/www/api/getproject.php',
        type: 'post',
        dataType: 'json',
        success:function(data){
          var html='';
          for(var i=0;i<data.length;i++){
            html+='<li>';
            html+='<div class="type">';
            html+='<span>'+data[i].category+'</span>';
            html+='</div>';
            html+='<div class="showpic">';
            html+='<img src="'+data[i].image+'" alt="">';
            html+='</div>';
            html+='<div class="companyname">';
            html+='<span>公司名称：</span><span>'+data[i].name+'</span>';
            html+='</div>';
            html+='<div class="describe">';
            html+='<span>描述：</span><span>'+data[i].description+'</span>';
            html+='</div>';
            html+='<div class="detail">';
            html+='<span>详情：</span><span>'+data[i].detail+'</span>';
            html+='</div>';
            html+='<div class="tech">';
            html+='<span>涉及的技术：</span><span>'+data[i].tech+'</span>';
            html+='</div>';
            html+='</li>';
          }
        $('#scroller ul').html(html);
        setTimeout(function(){
          myScroll.refresh();
        },250)
        
        }
      })   
    }
    
    function scan(){
      $.ajax({
        type:'post',
        url:'http://www.lewisye.online/php/getsign.php',
        data:{url:window.location.href},
        dataType:'json',
        success:function(data){
          wx.config({
            debug: false,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: [
              // 所有要调用的 API 都要加到这个列表中
              'scanQRCode',
              'chooseImage'
            ]
          });

          $('#scan').on('tap',function(){
            wx.scanQRCode({
              needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
              scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
              success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
              }
            });
          })
        }
      })
    }